package com.zhentao.utils.common;

/**
 * ThreadLocal ：
 * 1.通过get/set方法存取数据
 * 2.线程安全
 * 3.用完记得删除 调用remove释放内存
 *
 * @author zhangxinlong
 */
public class ThreadLocalUtil {
    //提供ThreadLocal对象
    private static final ThreadLocal THREAD_LOCAL = new ThreadLocal();

    //根据键获取值 提供泛型T 根据存储的类型 强转成对应的类型
    public static <T> T get() {
        return (T) THREAD_LOCAL.get();
    }

    //存储键值对
    public static void set(Object value) {
        THREAD_LOCAL.set(value);
    }

    //清楚ThreadLocal 防止内存泄露
    public static void remove() {
        THREAD_LOCAL.remove();
    }
}
